//
//  JourneyDetailViewController.m
//  WildDonkey
//
//  Created by 孙俊 on 15/4/1.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "JourneyDetailViewController.h"
#import "AFNetworking.h"
@interface JourneyDetailViewController ()
//菊花
@property (nonatomic,retain) UIActivityIndicatorView *activityIndicator;

@property (nonatomic,retain) NSString *content;
@end

@implementation JourneyDetailViewController

- (void)dealloc
{
	[_yid release];
	[_webView release];
	[super dealloc];
}

#pragma mark Touch
//- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//{
//	[self.navigationController setNavigationBarHidden:YES animated:NO];
//	[self.navigationController setToolbarHidden:YES  animated:NO];
//}

- (void)viewWillAppear:(BOOL)animated
{
	[self.navigationController setNavigationBarHidden:YES animated:NO];
}

-(void) viewDidAppear:(BOOL)animated
{
	[self.navigationController setNavigationBarHidden:NO animated:NO];
}

//图片加载菊花
- (void)loading
{
	_activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyleWhiteLarge)];
	self.activityIndicator.frame = CGRectMake(self.view.center.x - 20, self.view.center.y - 40, 30, 30) ;
	self.activityIndicator.center = CGPointMake(self.view.center.x, self.view.center.y - 30);
	self.activityIndicator.color = [UIColor grayColor];
	[self.view addSubview:self.activityIndicator];
	[self.activityIndicator startAnimating];
	
	
}

- (void)loadData
{
	
	
	NSString *urlstr = [NSString stringWithFormat:@"http://mobileapp.roadqu.com/api/mobile/qunawan/poi/youji?token=5444d64083242&yid=%@",self.yid];
	
	
	_webView = [[JourneyDetailView alloc] initWithFrame:[UIScreen mainScreen].bounds];
	
	AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
	[manager GET:urlstr parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
		NSLog(@"xxxxxx");
		NSDictionary *dic1 = [responseObject valueForKey:@"data"];
		self.content = [dic1 valueForKey:@"content"];
		[self.webView loadHTMLString:self.content baseURL:nil];
		
		[self.view addSubview:self.webView];
		
	} failure:^(NSURLSessionDataTask *task, NSError *error) {
		//数据加载出错 ,弹出提示
		UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"网络错误" message:@"请刷新" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
		[errorAlert show];
		
	}];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
	//[self.view setBackgroundColor:[UIColor redColor]];
	
	//消除导航栏遮挡
	self.edgesForExtendedLayout = UIRectEdgeNone;
	self.extendedLayoutIncludesOpaqueBars = NO;
	self.modalPresentationCapturesStatusBarAppearance = NO;
	
	[self loading];
	
	[self loadData];
	
	
	//数据请求 移至 loadData
	/*
 NSString *urlstr = [NSString stringWithFormat:@"http://mobileapp.roadqu.com/api/mobile/qunawan/poi/youji?token=5444d64083242&yid=%@",self.yid];
 
	
	_webView = [[JourneyDetailView alloc] initWithFrame:[UIScreen mainScreen].bounds];
	
	AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
	[manager GET:urlstr parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
 NSLog(@"xxxxxx");
 NSDictionary *dic1 = [responseObject valueForKey:@"data"];
 self.content = [dic1 valueForKey:@"content"];
 [self.webView loadHTMLString:self.content baseURL:nil];
 
 [self.view addSubview:self.webView];
 
	} failure:^(NSURLSessionDataTask *task, NSError *error) {
 UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"网络错误" message:@"请刷新" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
 [errorAlert show];
 
	}];

 */
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
